package com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.comm.SerialPort;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Created by leohe on 2017/7/29.
 */
@RestController
@RequestMapping("/serial/write")
public class testController {

    @Autowired
    private SerialPort serialPort;

    @PostMapping()
    public void serialWrite(){
        try {
            OutputStream outputStream = serialPort.getOutputStream();
            outputStream.write("123456789".getBytes());
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
